<template>
  <div :id="idName" :ref="idName" class="echart"></div>
</template>

<script>
export default {
  props: {
    echartData: {},
    idName: {},
  },
  data() {
    return {};
  },
  components: {},
  mounted() {
    this.echartsInit();
  },
  watch: {
    idName() {
      this.$nextTick(() => {
        this.echartsInit();
      });
    },
  },
  beforeDestroy() {},
  methods: {
    echartsInit() {
      this.$echarts.init(this.$refs[this.idName]).setOption({
        tooltip: {
          trigger: "axis",
          backgroundColor:'rgba(0,0,0,0.7)',
          borderColor:'rgba(0,0,0,0.8)',
          borderWidth:0,
          textStyle:{
            color:"#fff"
          },
          axisPointer: {
            lineStyle: {
              color: "#57617B",
            },
          },
        },
        grid: {
          top: "18%",
          left: "5%",
          right: "5%",
          bottom: "8%",
          containLabel: true,
        },
        xAxis: [
          {
            type: "category",
            boundaryGap: false,

            splitLine: {
              show: true,
              lineStyle: {
                color: "#243362", // Y轴内容线颜色（横线）
              },
            },
            axisTick: {
              show: false,
            },
            axisLine: {
              show:false,
              lineStyle: {
                color: "#fff", // X 轴坐标颜色
              },
            },
            axisLabel: {

            },
            data: this.echartData.date,
          },
        ],
        yAxis: [
          {
            type: "value",
            name: this.echartData.unit,
            nameTextStyle: {
              color: "#fff",
              fontSize: 12,
              align: "top",
              padding:[0,0,0,-20]
            },
            max: this.echartData.max,
            min: this.echartData.min,
            splitNumber:5,
            // 刻度标记
            axisTick: {
              show: false,
            },
            axisLine: {
              show: false,
              lineStyle: {
                // color: "#57617B", // Y轴坐标颜色
                color:'#fff'
              },
              
            },
            axisLabel: {
              margin: 6,
              textStyle: {
                fontSize: 12,
              },
              // 保留小数点3位
              // formatter: function (value, index) {           
              //  return value.toFixed(3);      
              // } 
            },
            splitLine: {
              show: true,
              lineStyle: {
                color: "#243362", // Y轴内容线颜色（横线）
              },
            },
          },
        ],
        series: [
          {
            type: "line",
            symbolSize: 5,
            lineStyle: {
              normal: {
                color: "RGBA(32, 169, 209, 1)", // 折线颜色
                width: 2,
                shadowColor: "rgba(34,150,243, 0.3)", // 折线阴影颜色
                shadowOffsetY: 5,
              },
            },
            itemStyle: {
              normal: {
                color: "RGBA(32, 169, 209, 1)", // 折线小圆点颜色
              },
            },
            areaStyle: {
              normal: {
                color: new this.$echarts.graphic.LinearGradient(
                  0,
                  0,
                  0,
                  1,
                  [
                    {
                      offset: 0,
                      color: "rgba(0, 162, 255, 0.6)", // 折线底下区域渐变色
                    },
                    {
                      offset: 0.5,
                      color: "rgba(7, 141, 255, 0)", // 折线底下区域渐变色
                    },
                    {
                      offset: 1,
                      color: "rgba(48, 255, 233, 0)", // 折线底下区域渐变色
                    },
                  ],
                  false
                ),
              },
            },
            data: this.echartData.data,
          },
        ],
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.echart {
  width: 100%;
  height: 160px;
  // top:-32px;
}
</style>
